<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class CreateGoodsTable extends Migration
{
	private $tableName = 'goods';
	private $tableComment = '商品管理表';
	private $primaryKey = 'id';

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create($this->tableName, function (Blueprint $table) {
			$table->increments(env('DB_CONNECTION') == 'oracle' ? strtoupper($this->primaryKey) : $this->primaryKey)->comment('商品id');
            $table->unsignedInteger('shop_id')->comment('店铺id')->default(0);
            $table->unsignedInteger('cate_id')->comment('商品分类id')->default(0);
            $table->string('shop_name',150)->comment('店铺名称')->nullable();
            $table->string('sign',300)->comment('标签')->nullable();
            $table->string('title', 100)->comment('商品标题');
            $table->mediumText('content')->comment('文章内容')->nullable();
            $table->string('default_img', 255)->comment('头图')->nullable();
            $table->string('address', 100)->comment('地址')->nullable();
            $table->unsignedTinyInteger('send_type')->comment('是否包邮，1包邮，0不包邮')->default(1);
            $table->string('sizes', 500)->comment('型号')->nullable();
            $table->unsignedTinyInteger('is_exchange')->comment('是否积分兑换，1是，0不显示')->default(0);
            $table->unsignedBigInteger('score')->comment('积分兑换数')->default(0);
            $table->unsignedTinyInteger('is_show')->comment('是否显示，1显示，0不显示')->default(0);
            $table->unsignedTinyInteger('is_top')->comment('是否置顶，1置顶，0不置顶')->default(0);
            $table->unsignedTinyInteger('is_recommend')->comment('是否推荐，1推荐，0不推荐')->default(0);
            $table->unsignedTinyInteger('status')->comment('是否审核通过，1通过，0不通过')->default(0);
            $table->string('refund_msg',500)->comment('审核理由')->nullable();
            $table->unsignedTinyInteger('is_comment')->comment('是否允许评论，1允许，0不允许')->default(1);
            $table->unsignedInteger('views')->comment('查看数')->default(0);
            $table->unsignedInteger('comments')->comment('评论数')->default(0);
            $table->unsignedInteger('total')->comment('商品总数')->default(0);
            $table->unsignedInteger('rent_nums')->comment('商品剩余可购买总数')->default(0);
            $table->unsignedInteger('collection_num')->comment('收藏数')->default(0);
            $table->timestamps();

			if (env('DB_CONNECTION') == 'oracle') {
				$table->comment = $this->tableComment;
			}
		});

		if (env('DB_CONNECTION') == 'mysql') {
			DB::statement("ALTER TABLE `" . DB::getTablePrefix() . $this->tableName . "` comment '{$this->tableComment}'");
		}
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::dropIfExists($this->tableName);
		if (env('DB_CONNECTION') == 'oracle') {
			$sequence = DB::getSequence();
			$sequence->drop(strtoupper($this->tableName . '_' . $this->primaryKey . '_SEQ'));
		}
	}
}
